package com.sky.mapper.admin;


import com.github.pagehelper.Page;
import com.sky.annotation.AddAnnotation;
import com.sky.annotation.UpdateAnnotation;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.pojo.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return 员工对象
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);
    /*
    * 添加新员工
    * @param employee
    * @return
    */
    @Insert("insert into employee values (null, #{name},#{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status},#{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @AddAnnotation
    void add(Employee employee);

    /**
     * 分页查询员工
     * @param employeePageQueryDTO
     * @return 员工列表
     */
    Page<Employee> page(EmployeePageQueryDTO employeePageQueryDTO);
    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee findById(Long id);
    /**
     * 修改员工信息
     * @param employee
     */
    @Update("update employee set name = #{name}, username=#{username},phone = #{phone}, sex = #{sex}, id_number = #{idNumber}, status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @UpdateAnnotation
    void update(Employee employee);
    @Update("update employee set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);
    @Update("update employee set password = #{newPassword} where id = #{empId} and password = #{oldPassword}")
    void editPassword(PasswordEditDTO passwordEditDTO);
}
